/**
 * @file 全局布置
 * @author 叶永鸿
 * @description 在全局引用功能组件
 * @date 2021-7-11
 * @LastEditors 叶永鸿
 * @LastEditTime 2021-7-28
 */
import { createStore } from 'vuex'

enum loginStation {//0为未登录，1为emp登录，2为hr登录
  login_false = 0,
  login_em,
  login_hr,
}

interface LoginInfor {//对于登录的用户信息记录
  userName: string
  station: loginStation
  token: string//登录后从response.token中获取
}
interface HrSearch {//对于hr的搜索操作
  hrSearchNameOrTel: string
  hrSearchPage: number
  hrSearchTotalPage: number,
  hrSearchedInforDetail: any
  hrSearchedInfor: any
  hrSearchedInforList: any
}
interface HrManage {//对于hr的管理操作
  hrManagePage: number
  hrManageTotalPage: number
  hrManageSearchName: string
  hrManagePerPage: any
}
interface HrManageCheck {
  hrManageCheckInfor: any,
  hrManageCheckInforDetails: any,
  hrMangeCheckExperience: any,
}
interface EmpInformation {
  empInfor: any,
  empExp: any
}
interface EmpPerformanceForHr {
  performances: any,
  empExpid: string,
}
interface EmpPerformance {
  performances: any,
}


export interface LoginState {
  loginInfor: LoginInfor
  hrSearched: HrSearch
  hrManage: HrManage
  hrManageCheck: HrManageCheck
  hrEvaluation: string
  empInformation: EmpInformation
  empPerformanceForHr: EmpPerformanceForHr
  empPerformance: EmpPerformance
  manageIsOn:boolean
  loadding:boolean
}
const state: LoginState = {
  loginInfor: {
    userName: "",
    station: 0,
    token: "",
  } as LoginInfor,
  hrSearched: {
    hrSearchNameOrTel: "",
    hrSearchPage: 1,
    hrSearchTotalPage: 1,
    hrSearchedInforDetail: [],
    hrSearchedInfor: {},
    hrSearchedInforList: []
  } as HrSearch,
  hrManage: {
    hrManagePage: 1,
    hrManageTotalPage: 1,
    hrManageSearchName: "",
    hrManagePerPage: []
  } as HrManage,
  hrManageCheck: {
    hrManageCheckInfor: {},
    hrManageCheckInforDetails: {},
    hrMangeCheckExperience: [],
  } as HrManageCheck,
  empInformation: {
    empInfor: {},
    empExp: [],
  } as EmpInformation,
  empPerformanceForHr: {
    performances: [],
    empExpid: "",
  } as EmpPerformanceForHr,
  empPerformance:{
    performances: [],
  } as EmpPerformance,
  hrEvaluation: "",
  manageIsOn:true,
  loadding:false,
}


const getters = {
  getUserInfor(state?: LoginState) {//获取loginInfor信息
    return state?.loginInfor
  },
  // getUserInforName(state?: LoginState) {
  //   return state?.loginInfor.userName
  // },
  // getUserInforStation(state?: LoginState) {
  //   return state?.loginInfor.station
  // },
  // getUserInforToken(state?: LoginState) {
  //   return state?.loginInfor.token
  // },

  getUser_hrSearch(state?: LoginState) {//获取hrSearch信息
    return state?.hrSearched
  },
  // getUser_hrSearchedInforDetail(state?: LoginState) {
  //   return state?.hrSearched.hrSearchedInforDetail
  // },
  // getUser_hrSearchPage(state?: LoginState) {
  //   return state?.hrSearched.hrSearchPage
  // },
  // getUer_hrSearchNameOrTel(state?: LoginState) {
  //   return state?.hrSearched.hrSearchNameOrTel
  // },

  getUser_hrManage(state?: LoginState) {//获取hrManage信息
    return state?.hrManage;
  },

  getUer_hrManageCheck(state?: LoginState) {
    return state?.hrManageCheck
  },

  getHrEvaluation(state?: LoginState) {
    return state?.hrEvaluation
  },

  isLogined(state?: LoginState) {//用于验证是否登录
    return !(state?.loginInfor.station === 0)
  },


  isHr(state?: LoginState) {//用于验证是否hr登录
    return state?.loginInfor.station === 2
  },

  isEm(state?: LoginState) {//用于验证是否em登录
    return state?.loginInfor.station === 1
  },

  getEmpInformation(state?: LoginState) {
    return state?.empInformation
  },
  getEmpPerformanceForHr(state?:LoginState){
    return state?.empPerformanceForHr
  },
  getEmpPerformance(state?:LoginState){
    return state?.empPerformance
  },
  getManageIsOn(state?:LoginState){
    return state?.manageIsOn
  },
  isloading(state?:LoginState){
    return state?.loadding
  }
}
const mutations = {//定义mutations，第一个参数一定是state
  showloadding(state:LoginState, load:boolean) {
    state.loadding = load
  },

  login(state: LoginState, loginInfor: LoginInfor) {
    state.loginInfor = loginInfor;
  },
  hrSearch(state: LoginState, hrSearched: HrSearch) {
    state.hrSearched = hrSearched;
  },
  hrManage(state: LoginState, hrManage: HrManage) {
    state.hrManage = hrManage;
  },
  hrManageCheck(state: LoginState, hrManageCheck: HrManageCheck) {
    state.hrManageCheck = hrManageCheck;
  },

  hrEvaluate(state: LoginState, hrEvaluation: string) {
    state.hrEvaluation = hrEvaluation;
  },

  empInformation(state: LoginState, empInformation: EmpInformation) {
    state.empInformation = empInformation
  },

  PerformanceForHr(state:LoginState,performanceForHr:EmpPerformanceForHr){
    state.empPerformanceForHr = performanceForHr
  },

  Performance_Mine(state:LoginState,performance:EmpPerformance){
    state.empPerformance = performance
  },

  isOnChange(state:LoginState,isOn:boolean){
    state.manageIsOn = isOn
  },
  

}

export default createStore({
  state: state,
  getters: getters,
  mutations: mutations,
  actions: {
    setloadding(context,load){
      context.commit("showloadding",load);
    }
  },
  modules: {
  }
})
